// pages/pro/pro.js
Page({
  data: {
    gender: '',
    avatarUrl: '',
    nickName: '',
    idNumber: '', // 身份证号
    phone: '', // 手机号
    id: '',
    token: '' // 存储 Token
  },

  onLoad() {
    this.fetchUserInfo();
  },

  fetchUserInfo() {
    const that = this;
    const token = wx.getStorageSync('token'); // 获取 Token
    console.log(token)
    const app = getApp();
    wx.request({
      url: `${app.globalData.baseUrl}/user/get-user-info`,
      method: 'GET',
      header: {
        'authentication': token
      },
      success(res) {
        if (res.statusCode === 200) {
          const userInfo = res.data.data;
          that.setData({
            nickName: res.data.data.name,
            idNumber: res.data.data.idNumber,
            phone: res.data.data.phone,
            gender: res.data.data.sex,
            id: res.data.data.id
          });
        } else {
          wx.showToast({
            title: '获取用户信息失败',
            icon: 'none'
          });
        }
      },
      fail() {
        wx.showToast({
          title: '请求失败',
          icon: 'none'
        });
      }
    });
  },
  editProfile: function () {
    // 跳转到修改个人信息的页面
    wx.navigateTo({
      url: '/pages/ed/ed' // 修改个人信息页面的路径
    });
  }
});